#
# Comic.py
# (c) 2008 Will Baker.
#

import os
import re

from Page import Page
from Metadata import Metadata

class Comic:
    """
    A Comic.
    """
    def __init__( self, path ):
        self.path = os.path.normpath(path)
        (self.name, self.extension) = os.path.splitext( os.path.basename(self.path) )
        self.page_count = 0
        self.tags = {}
        self.metadata = Metadata()
        
    def is_supported_image_format( self, path ):
        """
        Checks whether an image file is supported (by extension)
        """
        (_, ext) = os.path.splitext( path )
        
        return ext.lower() in ['.jpeg', '.jpg', '.gif', '.png']
        
    def sort_pages( self, filenames ):
        def filename_sort( a, b ):
            return cmp( a, b )
            
        filenames.sort( filename_sort )

    def __repr__( self ):
        return self.name
